
# and contains methods for transmitting and recieving
# even use this class.
class Server
     attr_reader :ip, :port
     
     # Address is the server ip/domain - for example, "saphrix.com" or "67.202.107.101"
     def initialize(address, port=6667)
          port = port.to_s
          puts "Connecting to #{address}:#{port}"
          @ip = address
          @socket = TCPSocket.new(address, port)
          puts "Connected."
     end
     
     #
     #    [:params] _(optional)_ => The extra parameters to add on to the message, in the form of an array
     def send(message)
          unless message[:command]
               return false
          end
          command = message[:command].upcase
          if message[:params]
               params = message[:params]
               last = params[params.length - 1 ].split(" ")
               unless last.length == 1
                    parameters = params[0..(params.length - 2)].join(" ") + " :" + last.join(" ")
               else
                    parameters = params.join(" ")
               end
          end
          @socket.print("#{command} #{parameters}\r\n")
     end
     
     def check
          return @socket.recv(512)
     end
end
